#include<iostream>
using namespace std;
class Person
{
public:
    Person();
    virtual ~Person();
    virtual void work() = 0;
    void setName(const string &name);
    string getName() const;
protected:
    string name;
};

Person::Person()
{
    cout << "Person()" << endl;
}

Person::~Person()
{
    cout << "~Person()" << endl;
}

void Person::setName(const string &name)
{
    this->name = name;
}

string Person::getName() const
{
    return name;
}

class Student : public Person
{
public:
    Student();
    virtual ~Student();
    virtual void work();
};

Student::Student()
{
    cout << "Student()" << endl;
}

Student::~Student()
{
    cout << "~Student()" << endl;
}

void Student::work()
{
    cout << "Student::work()" << endl;
}

int main()
{
    // err：抽象类不能实例化
    // Person *per = new Person;

    // 如果在派生类中不实现纯虚函数，派生类也将是抽象类
    Person *stu = new Student;
    stu->work();
    stu->setName("ceshi");
    cout << "id: " << stu->getName() << endl;
    delete stu;
    stu = nullptr;
    return 0;
}